﻿Type=Activity
Version=3.15
@EndOfDesignText@
#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: True
#End Region

Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.
	
	Dim V_XM As String
	Dim V_CH As String
	Dim V_BHID As Int
	Dim V_RYRQ As Int
	Dim V_RQ As String
	
	Dim FRQ As Long
End Sub

Sub Globals
	'These global variables will be redeclared each time the activity is created.
	'These variables can only be accessed from this module.

	Dim wbvTWD As WebView
	Dim imgTWDBG As ImageView
	
	Dim HttpJobTool As HttpJob
End Sub

Sub Activity_Create(FirstTime As Boolean)
	Activity.LoadLayout("FormBHTWInfo")
	Activity.Title = "病人体温单信息-"  & V_CH & " " &V_XM 
	
	'wbvTWD.Initialize("wbvTWD") '不需要初始化
'	imgTWDBG.Color = Colors.Transparent
'	imgTWDBG.Height = 1100
'	imgTWDBG.Width = 720
'	imgTWDBG.SetBackgroundImage(LoadBitmap(PublicVar.GV_ImagePath,"twdbg.jpg"))
	'imgTWDBG.Bitmap = LoadBitmap(PublicVar.GV_ImagePath,"twd.jpg")
	
	wbvTWD.Color =  Colors.Transparent
	'wbvTWD.SetBackgroundImage(LoadBitmap(PublicVar.GV_ImagePath,"twdbg.jpg"))
	
	InitLayOut
End Sub

Sub Activity_Resume
	RefreshData
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub InitLayOut
	'高级菜单
	Activity.AddMenuItem("首页","MenuItemAdv")
	Activity.AddMenuItem("上页","MenuItemAdv")
	Activity.AddMenuItem("下页","MenuItemAdv")
	Activity.AddMenuItem("末页","MenuItemAdv")
End Sub

Sub MenuItemAdv_Click
	Dim iRYRQ As Long
	
	DateTime.DateFormat = "yyyyMMdd"  '月是M，大写
	iRYRQ = PublicVar.DRQ2B4ARQ(V_RYRQ)

	If Sender = "首页" Then
		FRQ = iRYRQ	

	Else If Sender = "上页" Then
		FRQ = FRQ - DateTime.TicksPerDay * 7
		FRQ = Max(FRQ,iRYRQ)
		
	Else If Sender = "下页" Then
		FRQ = FRQ + DateTime.TicksPerDay * 7
		FRQ = Min(FRQ,DateTime.Now)		
		
	Else
		FRQ = DateTime.Now
	End If
	
	V_RQ = DateTime.Date(FRQ)	
	RefreshData
End Sub	

Sub RefreshData 
	Dim sURL,sSession,sText,sBHID,sRYRQ,sRQ As String
	
	sSession = PublicVar.GV_DesTool.Base64encrypt(PublicVar.GV_UserSession)
	sBHID = PublicVar.GV_DesTool.Base64encrypt(V_BHID)
	
	sRYRQ = PublicVar.GV_DesTool.Base64encrypt(V_RYRQ)
	sRQ = PublicVar.GV_DesTool.Base64encrypt(V_RQ)
	
	sText = "Session=" & sSession & "&BHID=" & sBHID & "&RYRQ=" & sRYRQ & "&RQ=" & sRQ
	
	sURL = PublicVar.GetServerUrl&"/getbhtwinfo"
	HttpJobTool.Initialize("Job1",Me)
	HttpJobTool.PostString(sURL,sText)
	
	ProgressDialogShow("正在获取数据，请稍候...")	
	
End Sub

Sub JobDone (Job As HttpJob)
   Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
   If Job.Success = True Then
      If Job.JobName = "Job1" Then
				HttpJobSuccess(Job)
      End If
   Else
		HttpJobError(Job)
   End If
   Job.Release
End Sub

Sub HttpJobSuccess (Job As HttpJob) 
	Dim sResult,sCode,sData,sHtml As String
	Dim mapResult As Map
	
	ProgressDialogHide
	
	sResult = Job.GetString.Trim
	
	PublicVar.GV_JSonTool.Initialize(sResult)
	mapResult = PublicVar.GV_JSonTool.NextObject
	
	sCode = mapResult.Get("Code")
	If sCode<>"0" Then
		sResult = mapResult.Get("Message")
		ToastMessageShow("获取数据失败"&CRLF &sResult, True)	
		
		PublicVar.CheckSession(sCode)
		Return
	End If
	
	sData = mapResult.Get("Data")
	If sData ="" Then
		ToastMessageShow("获取数据失败"&CRLF &"返回的数据为空", True)	
		Return	
	
	End If
	
	sData = PublicVar.GV_DesTool.Base64decrypt(sData)
	sData = PublicVar.GetServerUrl& sData
	
	sHtml = "<html><body><img src='" & sData& "' /></body><html>"
	
	Log(sHtml)
	wbvTWD.LoadHtml(sHtml)
End Sub

Sub HttpJobError (Job As HttpJob) 
	Dim sMsg As String
	ProgressDialogHide
	
	Log("Error: " & Job.ErrorMessage)
	sMsg = "获取病人医嘱信息失败."& CRLF & Job.ErrorMessage 
  ToastMessageShow(sMsg, True)
End Sub


